package ${basePackage}.service.${modulePackage};

import ${basePackage}.base.exception.BizException;
import ${basePackage}.base.result.PageResult;
import ${basePackage}.base.service.BaseServiceImpl;
import ${basePackage}.base.tree.TreeUtil;
import ${basePackage}.enums.DeleteFlagEnum;
import ${basePackage}.enums.UseFlagEnum;
import ${basePackage}.entity.${domainName};
import ${basePackage}.mapper.${domainName}Mapper;
import ${basePackage}.model.${modulePackage}.add.${moduleName}AddParams;
import ${basePackage}.model.${modulePackage}.add.${moduleName}AddVo;
import ${basePackage}.model.${modulePackage}.delete.${moduleName}DeleteParams;
import ${basePackage}.model.${modulePackage}.delete.${moduleName}DeleteVo;
import ${basePackage}.model.${modulePackage}.detail.${moduleName}DetailParams;
import ${basePackage}.model.${modulePackage}.detail.${moduleName}DetailVo;
import ${basePackage}.model.${modulePackage}.list.${moduleName}ListParams;
import ${basePackage}.model.${modulePackage}.list.${moduleName}ListVo;
import ${basePackage}.model.${modulePackage}.page.${moduleName}PageParams;
import ${basePackage}.model.${modulePackage}.page.${moduleName}PageVo;
import ${basePackage}.model.${modulePackage}.tree.${moduleName}TreeParams;
import ${basePackage}.model.${modulePackage}.tree.${moduleName}TreeVo;
import ${basePackage}.model.${modulePackage}.update.${moduleName}UpdateParams;
import ${basePackage}.model.${modulePackage}.update.${moduleName}UpdateVo;
import ${basePackage}.utils.bean.BeansHelper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;


/**
 * @version: ${version}
 * @author: ${author}
 * @date: ${date?string("yyyy/MM/dd HH:mm")}
 * @description: ${name}->${tableName}
 */
@Slf4j
@Service
public class ${moduleName}ServiceImpl extends BaseServiceImpl<${domainName}Mapper, ${domainName}> implements ${moduleName}Service {


    /**
     * 分页接口-未实现
     */
    @Override
    public PageResult<${moduleName}PageVo> page(${moduleName}PageParams params) {
        LambdaQueryWrapper<${domainName}> ${domainName?uncap_first}LambdaQueryWrapper = new LambdaQueryWrapper<>();
        //写条件
        ${domainName?uncap_first}LambdaQueryWrapper.eq(${domainName}::getDeleteFlag, DeleteFlagEnum.NO_DELETE.getCode());
        Page<${domainName?cap_first}> pageData = this.page(new Page(params.getPageNum(), params.getPageSize()), ${domainName?uncap_first}LambdaQueryWrapper);
        PageResult<${moduleName}PageVo> result = BeansHelper.convert(pageData, ${moduleName}PageVo.class);
        return result;
    }

    /**
    * 树接口-未实现
    */
    @Override
    public List<${moduleName}TreeVo> tree(${moduleName}TreeParams params) {
        LambdaQueryWrapper<${domainName}> ${domainName?uncap_first}LambdaQueryWrapper = new LambdaQueryWrapper<>();
        //写条件
        List<${domainName?cap_first}> pageData = this.list(${domainName?uncap_first}LambdaQueryWrapper);
        List<${moduleName}TreeVo> resultList = BeansHelper.convert(pageData, ${moduleName}TreeVo.class);
        List<${moduleName}TreeVo> resultTree = TreeUtil.listToTree(resultList);
        return resultTree;
    }

   /**
    * 列表接口-未实现
    */
   @Override
   public List<${moduleName}ListVo> list(${moduleName}ListParams params) {
       LambdaQueryWrapper<${domainName}> ${domainName?uncap_first}LambdaQueryWrapper = new LambdaQueryWrapper<>();
       //写条件
       List<${domainName?cap_first}> pageData = this.list(${domainName?uncap_first}LambdaQueryWrapper);
       List<${moduleName}ListVo> result = BeansHelper.convert(pageData, ${moduleName}ListVo.class);
       return result;
   }

    /**
     * add 接口-未实现
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ${moduleName}AddVo add(${moduleName}AddParams params) {
        LambdaQueryWrapper<${domainName}> ${domainName?uncap_first}LambdaQueryWrapper = new LambdaQueryWrapper<>();
        //${domainName?uncap_first}LambdaQueryWrapper.eq(${domainName}::getStoreId, params.getStoreId());
        ${domainName} ${domainName?uncap_first}Old = this.getOne(${domainName?uncap_first}LambdaQueryWrapper);
        if (${domainName?uncap_first}Old != null) {
            throw new BizException("数据已存在");
        }
        ${domainName} ${domainName?uncap_first} = new ${domainName}();
        //set属性
        //${domainName?uncap_first}
        boolean flag = this.save(${domainName?uncap_first});
        ${moduleName}AddVo result = new ${moduleName}AddVo();
        return result;
    }

     /**
      * update 接口-未实现
      */
     @Transactional(rollbackFor = Exception.class)
     @Override
     public ${moduleName}UpdateVo update(${moduleName}UpdateParams params) {
         //主键查询
         ${domainName} ${domainName?uncap_first} = this.getById(params.getId());
         if(${domainName?uncap_first} == null){
             throw new BizException("数据不存在");
         }
         //${domainName?uncap_first}.set相关属性;
         boolean flag = this.updateById(${domainName?uncap_first});
         ${moduleName}UpdateVo result = new ${moduleName}UpdateVo();
         return result;
     }

     /**
      * detail 接口-未实现
      */
     @Override
     public ${moduleName}DetailVo detail(${moduleName}DetailParams params) {
         ${domainName} ${domainName?uncap_first} = this.getById(params.getId());
         ${moduleName}DetailVo result = BeansHelper.convert(${domainName?uncap_first}, ${moduleName}DetailVo.class);
         return result;
     }

    /**
     * delete 接口-未实现
     */
    @Override
    public ${moduleName}DeleteVo delete(${moduleName}DeleteParams params) {
        ${domainName} ${domainName?uncap_first} = this.getById(params.getId());
        if (${domainName?uncap_first} == null || Objects.equals(${domainName?uncap_first}.getDeleteFlag(), DeleteFlagEnum.DELETE.getCode())) {
            throw new BizException("数据不存在或已删除");
        }
        ${domainName?uncap_first}.setDeleteFlag(DeleteFlagEnum.DELETE.getCode());
        this.updateById(${domainName?uncap_first});
        ${moduleName}DeleteVo result = BeansHelper.convert(${domainName?uncap_first}, ${moduleName}DeleteVo.class);
        return result;
    }

}
